/*
 * @Author: szx
 * @Date: 2021-12-28 16:20:17
 * @LastEditTime: 2021-12-28 16:45:20
 * @Description:
 * @FilePath: \leetcode\400-499\491\491.js
 */
/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var findSubsequences = function (nums) {
    const res = [];
    const len = nums.length;
    const path = [];
    const backtrack = (index) => {
        if (path.length >= 2) {
            res.push(Array.from(path));
        }
        let arr = [];
        for (let i = index; i < len; i++) {
            if ((path.length && nums[i] < path[path.length - 1]) || arr[nums[i] + 100]) continue;
            path.push(nums[i]);
            arr[nums[i] + 100] = 1;
            backtrack(i + 1);
            path.pop();
        }
    };
    backtrack(0);
    return res;
};
// [4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]
console.log(findSubsequences([1, 2, 1, 1]));
